if [ "$1" = "start" ]; then
        sudo nohup gunicorn -w 4 -b 0.0.0.0:5000 Synthesiser:app &
	if [ $? -eq 0 ]; then
                echo -e "\033[32m 混音服务开启成功 \033[0m"
        else
                echo -e "\033[31m 混音服务开启失败 \033[0m"
        fi
elif [ "$1" = "stop" ]; then
	check=$(ps aux | grep -c gunicorn | awk -F' ' '{print $1}' | awk 'NR==1{print}')
	if [ "$check" -eq 1 ]; then
		echo -e "\033[31m 混音服务未开启 \033[0m"
	else
        	pid=$(ps aux | grep gunicorn | awk -F' ' '{print $2}' | awk 'NR==1{print}')
        	kill $pid
        	if [ $? -eq 0 ]; then
                	echo -e "\033[32m 混音服务关闭成功 \033[0m"
        	else
                	echo -e "\033[31m 混音服务关闭失败 \033[0m"
        	fi
	fi
elif [ "$1" = "restart" ]; then
	check=$(ps aux | grep -c gunicorn | awk -F' ' '{print $1}' | awk 'NR==1{print}')
	if [ "$check" -eq 1 ]; then
		echo -e "\033[31m 混音服务未开启 \033[0m"
		sudo nohup gunicorn -w 4 -b 0.0.0.0:5000 Synthesiser:app &
        	if [ $? -eq 0 ]; then
                	echo -e "\033[32m 混音服务开启成功 \033[0m"
        	else
                	echo -e "\033[31m 混音服务开启失败 \033[0m"
        	fi
	else
		pid=$(ps aux | grep gunicorn | awk -F' ' '{print $2}' | awk 'NR==1{print}')
        	kill $pid
        	if [ $? -eq 0 ]; then
                	echo -e "\033[32m 混音服务关闭成功 \033[0m"
                	sudo nohup gunicorn -w 4 -b 0.0.0.0:5000 Synthesiser:app &
			if [ $? -eq 0 ]; then
                        	echo -e "\033[32m 混音服务重启成功 \033[0m"
                	else
                        	echo -e "\033[31m 混音服务重启失败 \033[0m"
                	fi
        	fi
	fi
elif [ "$1" = "" ]; then
        echo -e "\033[31m please use [start|stop|restart] to run this shell \033[0m"
fi
